package work06;

import java.io.File;
import java.io.IOException;
import java.util.Date;

public class Test06 {
    public static void main(String[] args) throws IOException {
        String filePath = "D:/MyFolder";
        String fileName = "test.txt";
        File myFolder = new File(filePath);
        if (!myFolder.exists()){
            myFolder.mkdirs();
        }
        File myFile = new File(filePath + "/" + fileName);
        if (!myFile.exists()){
            myFile.createNewFile();
        }
        System.out.println("----------------------------------------");
        System.out.println("文件绝对路径：" + myFile.getAbsolutePath());
        System.out.println("文件名称:"+myFile.getName());
        System.out.println("文件父节点:"+myFile.getParent());
        System.out.println("是文件夹吗？:"+myFile.isDirectory());
        System.out.println("是文件吗？:"+myFile.isFile());
        System.out.println("是隐藏的吗？:"+myFile.isHidden());
        System.out.println("是可写的吗？:"+myFile.canWrite());
        System.out.println("是可执行的吗？:"+myFile.canExecute());
        System.out.println("最后一次修改时间？:"+new Date(myFile.lastModified()));
        System.out.println("文件的大小:"+myFile.length() +"字节");
        System.out.println("------------------------");
        File[] files = myFile.listFiles();
        System.out.println("文件：");
        for (File file : files){
            if (file.isFile()){
                System.out.println("\t" + file.getName());
            }
        }
        System.out.println("文件夹：");
        for (File file : files){
            if (file.isDirectory()){
                System.out.println("\t" + file.getName());
            }
        }
        File[] roots = File.listRoots();
        for (int i = 0;i < roots.length;i++){
            System.out.println(roots[i]);
            System.out.println("空闲空间：" + roots[i].getFreeSpace());
            System.out.println("可用空间：" + roots[i].getUsableSpace());
            System.out.println("总空间：" + roots[i].getTotalSpace());
            System.out.println();
        }
        System.out.println("---------------------------------");
    }
}
